package com.atguigu.cart.exception;

import com.atguigu.common.utils.Message;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 **/
@RestControllerAdvice
public class RuntimeExceptionHandler {

    /**
     * 全局统一异常处理
     * @param exception
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public Message handler(RuntimeException exception) {
        return Message.error(exception.getMessage());
    }

    @ExceptionHandler(CartExceptionHandler.class)
    public Message userHandler(CartExceptionHandler exception) {
        return Message.error("购物车无此商品！");
    }
}
